﻿using DataChangeTools.Api.Service;
using DataChangeTools.Api.Services;
using DataChangeTools.AutoUpdater.ViewModels;
using DataChangeTools.AutoUpdater.Views;
using DataChangeTools.SplashModule.Interfaces;
using DataChangeTools.SplashModule.ViewModels;
using DataChangeTools.SplashModule.Views;
using DataChangeTools.ViewModel;
using DataChangeTools.Views;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;

namespace DataChangeTools
{
    public class Bootstrapper : Prism.Unity.PrismBootstrapper
    {
        protected override void RegisterTypes(Prism.Ioc.IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainWindow, MainViewModel>();
            containerRegistry.RegisterForNavigation<BatchRenameWithImage, BatchRenameWithImageViewModel>();

            containerRegistry.RegisterForNavigation<AutoUpdaterView, AutoUpdaterViewModel>();

            containerRegistry.RegisterForNavigation<ImageViewDialog, ImageViewDialogViewModel>();

            containerRegistry.RegisterForNavigation<SplashView, SplashViewViewModel>();

            containerRegistry.RegisterDialog<AutoUpdaterView>("AutoUpdaterView");

            containerRegistry.RegisterDialog<ImageViewDialog>("ImageViewDialog");

            containerRegistry.RegisterSingleton<IShell, MainWindow>();
            //注冊服務
            RegistryService(containerRegistry);
            RegistryServiceKey(containerRegistry);
        }


        public void RegistryService(Prism.Ioc.IContainerRegistry containerRegistry)
        {
            containerRegistry.Register<IAutoUpdaterService, AutoUpdaterService>();
        }

        public void RegistryServiceKey(Prism.Ioc.IContainerRegistry containerRegistry)
        {
            try
            {
                containerRegistry.Register<HttpClient>();

                // 注册 HttpRestClient 并配置 webUrl
                containerRegistry.Register<HttpRestClient>(() =>
                {
                    var httpClient = Container.Resolve<HttpClient>();
                    var webUrl = "http://81.70.79.122:8070"; // 替换为你的 API URL
                    //var webUrl = "http://localhost:5296"; // 替换为你的 API URL
                    return new HttpRestClient(webUrl);
                });
            }
            catch (Exception e)
            {

                throw;
            }
        }




        protected override DependencyObject CreateShell()
        {
            var shell = Container.Resolve<IShell>();
            return (DependencyObject)shell;
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<DataChangeTools.SplashModule.Module>();

            moduleCatalog.AddModule<DataChangeTools.AutoUpdater.AutoUpdaterModule>();
        }
    }
}
